Fix MPS device support for Apple Silicon Macs#26
Open
btebedo wants to merge 1 commit intoubisoft:mainfrom
Open
Fix MPS device support for Apple Silicon Macs#26btebedo wants to merge 1 commit intoubisoft:mainfrom
btebedo wants to merge 1 commit intoubisoft:mainfrom
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fix MPS device support for Apple Silicon Macs
Problem
StableDiffusion.setup()used a binary device check (cudaorcpu) that ignored Apple's MPS backend. On Apple Silicon,self.deviceresolved tocpu, while ComfyUI's model management moved the UNet to MPS. This caused a device mismatch —encode_textproduced CPU-resident embeddings that the MPS-resident UNet rejected at the cross-attention layer:Changes (stable_diffusion.py)
torch.device("cuda" if torch.cuda.is_available() else "cpu")with a three-way check: CUDA → MPS → CPU..to()captures return value — changedself.text_encoder.to(...)toself.text_encoder = self.text_encoder.to(...)so the reference always points to the materialized model, which matters for lazy/meta tensors on MPS.encode_text— addedself.text_encoder = self.text_encoder.to(self.device)before inference to force weight materialization, preventing MPS failures from lazy-loaded embedding weights.No functional change on CUDA or CPU.